<?php
// $Id$

include_once('BaseModel.class.php');

class PresetMessagesLookupModel extends BaseModel
{
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='')
    {
        $where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '{$search['searchtext']}%'" : "WHERE 1";

        if (is_null($offset)) {
            $query = "SELECT COUNT(*)
                      FROM preset_messages $where AND active=1";
        } else {
            $query = "SELECT * FROM preset_messages $where AND active=1 ORDER BY $by $sort LIMIT $offset,$limit";

        }
        return $this->query($query, true);
    }

    function detail ($id)
    {
		$query = "SELECT * FROM preset_messages  WHERE id ='$id'";
        return $this->select_one($query, true);
    }

    /*
     * Add preset_messages and return the new preset_messages_id
     *
     */
    function ins($detail)
    {
        return $this->insert('preset_messages', $detail);
        return $this->last_insert_id('preset_messages');
    }

    /*
     * Update preset_messages for a particular preset_messages_id
     *
     */
    function edit ($id, $detail)
    {
        return $this->update('preset_messages', $detail, "id = '$id'");
    }

    /*
     * Delete preset_messages detail for a particular preset_messages_id
     *
     */
    function deactivate ($id)
    {
        $query = "UPDATE preset_messages SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id)
    {
        $query = "UPDATE preset_messages SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
